package com.steven.realServer.controller;

import com.alibaba.fastjson.JSONObject;
import com.steven.realServer.pojo.EmailInfo;
import com.steven.realServer.pojo.UserInfo;
import com.steven.realServer.service.LoginService;
import com.steven.realServer.utils.ResultUtils;
import com.steven.realServer.utils.SendEmailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    @Autowired
    private LoginService service;
    @Autowired
    SendEmailUtils sendEmailUtils;

    @PostMapping("/auth/login")
    public JSONObject login(UserInfo info){
        return service.login(info);
    }

    @PostMapping("/auth/loginQuick")
    public JSONObject loginQuick(UserInfo info){
        return service.loginQuick(info);
    }

    @PostMapping("/auth/signUp")
    public JSONObject signUp(UserInfo info){
        return service.signUp(info);
    }

    @PostMapping("/auth/sendCode")
    public JSONObject sendCode(EmailInfo info){
        sendEmailUtils.sendRegisterCode(info.getEmail(),info.getCode());
        JSONObject object = new JSONObject();
        object.put("msg","success");
        return ResultUtils.makeResult(0, object);
    }
}
